package com.asset.dispoal.file.replyDetail;

import com.asset.dispoal.file.replyDetail.api.FileReplyDetailService;
import com.asset.dispoal.file.replyDetail.dto.FileReplyExportRequest;
import com.asset.dispoal.file.replyDetail.dto.FileReplyMonthDetailStatistics;
import com.asset.dispoal.file.replyDetail.dto.FileReplyQueryRequest;
import com.asset.dispoal.file.replyDetail.dto.FileReplyRequest;
import com.asset.dispoal.file.replyDetail.dto.FileReplyYearDetailStatistics;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tech.mhuang.pacebox.core.util.StringUtil;
import tech.mhuang.pacebox.springboot.protocol.Result;

import javax.servlet.http.HttpServletResponse;

@RestController
@Api(value = "回款表管理", tags = "回款表管理")
@RequestMapping("file/replyDetail")
public class FileReplyDetailController {

    @Autowired
    private FileReplyDetailService fileReplyDetailService;

    @PostMapping("/save")
    public Result save(@RequestBody FileReplyRequest request) {
        return fileReplyDetailService.save(request);
    }

    @PostMapping("/modify")
    public Result modify(@RequestBody FileReplyRequest request) {
        return fileReplyDetailService.modify(request);
    }

    @PostMapping("/page")
    public Result page(@RequestBody FileReplyQueryRequest request) {
        return fileReplyDetailService.page(request);
    }

    @GetMapping("/delete")
    public Result delete(String id) {
        if (StringUtil.isBlank(id)) {
            return Result.faild("配置id为空，请检查！！");
        }
        return fileReplyDetailService.delete(id);
    }

    @ApiOperation(value = "上传路径", notes = "上传路径")
    @GetMapping(value = "/uploadExcel")
    public Result uploadExcel(@ApiParam("文件路径") @RequestParam("filepath") String filepath) {
        fileReplyDetailService.uploadExcel(filepath);
        return Result.ok();
    }

    @GetMapping(value = "/monthDetailStatistics")
    public Result<FileReplyMonthDetailStatistics> monthStatistics() {
        return fileReplyDetailService.monthDetailStatistics();
    }

    @GetMapping(value = "/yearDetailStatistics")
    public Result<FileReplyYearDetailStatistics> yearStatistics(int year) {
        return fileReplyDetailService.yearDetailStatistics(year);
    }

    @GetMapping(value = "/export")
    public void export(HttpServletResponse response, FileReplyExportRequest request) {
        fileReplyDetailService.export(response, request);
    }
}